<html>
<head>
    <title>Search For</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <script type="text/javascript" src="<?=base_url()?>resource/js/jquery.js"></script>
    
    <link rel="stylesheet" href='<?=base_url()?>resource/css/style.css' type="text/css"/>
    
    <link rel="stylesheet" type="text/css" href="<?=base_url()?>resource/css/jquery.datetimepicker.css" />
    <script src="<?=base_url()?>resource/js/jquery.datetimepicker.js"></script>
    
    <link rel="stylesheet" type="text/css" href="<?=base_url()?>resource/css/jquery.autocompleter.css" />
    <script src="<?=base_url()?>resource/js/jquery.autocompleter.js"></script>
</head>
<body>
    <div class="choice-header">
        <h3><?=$title?></h3>
    </div>
    <div class="list-div">
        <?php echo form_open('profile/choice_workers'); ?>
        <table class="top-table">
            <tr>
                <td>Candidate List</td>
                <td width="240" class="center"><input type="text" placeholder="input candidate name" 
                    name="condition" value="<?=$condition?>"/></td>
                <td width="90" class="center"><input type="submit" value="Search" /></td>
                <td width="110" class="center"><input type="button" value="New" id="new"/></td>
            </tr>
        </table>
        <?php echo form_close(); ?>
        <input type="button" id="submit" value="submit" class="submit" />
        <table class="list-table">
            <tr>
                <th width="40">Check</th>
                <th>Name</th>
                <th width="100">Location</th>
                <th width="100">Speciality</th>
                <th width="60">Gender</th>
                <th width="100">Nationality</th>
                <th width="60">Age</th>
            </tr>
            <?php foreach ($candidates as $key => $value) {?>
            <tr>
                <td>
                    <input type="radio" name="workerid" value="<?=$value['id']?>"> 
                    <input type="hidden" name="companyid" id="companyid<?=$value['id']?>" value="<?=$value['companyid']?>"/>
                </td>
                <td id="tdname<?=$value['id']?>"><?=$value['name']?></td>
                <td><?=$value['locationstr']?></td>
                <td><?=$value['speciality']?></td>
                <td><?=$value['gender']==1?"man":"female"?></td>
                <td><?=$value['nationality']==1?"Malaysia":($value['nationality']==2?"China":($value['nationality']==3?"Vietnam":($value['nationality']==4?"Myanmar":($value['nationality']==5?"Bengal":"Other"))))?></td>
                <td><?=$value['age']?></td>
            </tr>
            <?php }
            if(count($candidates) == 0){?>
            <tr>
                <td colspan="7">
                    NO DATA
                </td>
            </tr>
            <?php }?>
        </table>
    </div>
<script>
$("#submit").click(function(){
    var returnval = "";
    var returnid = "";
    if("<?=$str?>" == "radio"){
        var candidate = window.opener.document.getElementById("candidate"); 
        var association = window.opener.document.getElementById("association");
        var id = $("input[name='workerid']:checked").val();
        if(id != undefined){
            var name = $("#tdname"+id).html();
            candidate.value = name;
            association.value = id;
        }
    }else{
        var workers =  window.opener.document.getElementById("workers"); 
        var workerids =  window.opener.document.getElementById("workersid"); 
        var agent = window.opener.document.getElementById("agent");
        var companyid = 0;
        $("input[type='radio']:checked").each(function(){
            var id = $(this).val();
            companyid = $("#companyid"+id).val();
            returnval = $("#tdname"+id).html();
            returnid = id;
        });
        if(returnval != ""){
            workers.value = returnval;
            workerids.value = returnid;
            agent.value = companyid;
        }
    }
    window.close();
});

$("#new").click(function(){
    var storage = window.localStorage; 
    storage.setItem("currentid","index");
    var url = '<?=base_url()?>index/new_candidate';
    window.opener.location.href=url; //重新定位父页面
    window.close();
});
</script>
</body>
</html>